package ystp.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import ystp.dao.ShengchanqiyelinxuanzhongjianjieguoMapper;
import ystp.model.Shengchanqiyelinxuanzhongjianjieguo;
import ystp.model.ShengchanqiyelinxuanzhongjianjieguoExample;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ShengchanqiyelinxuanzhongjianjieguoService {

    @Resource
    public ShengchanqiyelinxuanzhongjianjieguoMapper ddMapper;

    public boolean add(Shengchanqiyelinxuanzhongjianjieguo ppShengchanqiyelinxuanzhongjianjieguo){
        return ddMapper.insert(ppShengchanqiyelinxuanzhongjianjieguo)==1;
    }

    public boolean modify(Shengchanqiyelinxuanzhongjianjieguo ppShengchanqiyelinxuanzhongjianjieguo){
        return ddMapper.updateByPrimaryKey(ppShengchanqiyelinxuanzhongjianjieguo)==1;
    }

    public Shengchanqiyelinxuanzhongjianjieguo findByDetailId(String ppDetailId){
        ShengchanqiyelinxuanzhongjianjieguoExample mmExample = new ShengchanqiyelinxuanzhongjianjieguoExample();
        mmExample.createCriteria().andDetailidEqualTo(ppDetailId);
        return ddMapper.selectByExample(mmExample).size()==1?ddMapper.selectByExample(mmExample).get(0):null;
    }

    public Shengchanqiyelinxuanzhongjianjieguo findByDetailIdAndLunci(String ppDetailId,int ppLunci){
        ShengchanqiyelinxuanzhongjianjieguoExample mmExample = new ShengchanqiyelinxuanzhongjianjieguoExample();
        mmExample.createCriteria().andDetailidEqualTo(ppDetailId).andLunciEqualTo(ppLunci);
        return ddMapper.selectByExample(mmExample).size()==1?ddMapper.selectByExample(mmExample).get(0):null;
    }

    public int countPassByPingui(String ppPingui,int ppLunci){
        ShengchanqiyelinxuanzhongjianjieguoExample mmExample = new ShengchanqiyelinxuanzhongjianjieguoExample();
        mmExample.createCriteria().andPinguiEqualTo(ppPingui).andLunciEqualTo(ppLunci).andStatusEqualTo(1);
        return ddMapper.countByExample(mmExample);
    }

    public int countPassCustom(String ppPingui,int ppLunci,String ppXiangmuId){
        Object mmCount = ddMapper.countPassCustom(ppPingui,ppLunci,ppXiangmuId);
        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }

    public boolean deleteByPingui(String ppPingui,String ppDetailId){
        ShengchanqiyelinxuanzhongjianjieguoExample mmExample = new ShengchanqiyelinxuanzhongjianjieguoExample();
        mmExample.createCriteria().andPinguiEqualTo(ppPingui).andDetailidEqualTo(ppDetailId);
        return ddMapper.deleteByExample(mmExample)>=0;
    }
}
